gtk-demo: Replace old code
authorBenjamin Otte <otte@redhat.com>
Fri, 3 Oct 2014 04:59:14 +0000 (06:59 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 3 Oct 2014 04:59:14 +0000 (06:59 +0200)
"Hey I know, let's do an easter egg!"
"What kind of easter egg?"
"We can nest lots of textviews!"
"Sounds cool!"
...
"But how does one see a textview inside a textview?"
"What do you mean?"
"Well, it just looks like black text on a white background."
"You mean it's the same as if we just duplicated the text?"
"Yeah!"
"Hrm, maybe we can put a frame around it."
"Sounds good. I'll stuff the textviews in a GtkFrame."
"What? Why? Let's use a GtkEventBox and override its background"
"Why is that a good idea when we have GtkFrame?"
"Because I said so!"
"Okay."

demos/gtk-demo/textview.c

index 775ede686431a8a0d23b4bb05f643f0ba999e0dc..9422759ef7c2aa24f04b82cb5e5edd79b3b840be 100644 (file)
@@ -539,26 +539,18 @@ recursive_attach_view (int                 depth,
                        GtkTextView        *view,
                        GtkTextChildAnchor *anchor)
 {
-  GtkWidget *child_view;
-  GtkWidget *event_box;
-  GdkRGBA color;
+  GtkWidget *child_view, *frame;
 
   if (depth > 4)
     return;
 
   child_view = gtk_text_view_new_with_buffer (gtk_text_view_get_buffer (view));
 
-  /* Event box is to add a black border around each child view */
-  event_box = gtk_event_box_new ();
-  gdk_rgba_parse (&color, "black");
-  gtk_widget_override_background_color (event_box, 0, &color);
+  /* Frame is to add a black border around each child view */
+  frame = gtk_frame_new (NULL);
+  gtk_container_add (GTK_CONTAINER (frame), child_view);
 
-  gtk_widget_set_halign (child_view, GTK_ALIGN_FILL);
-  gtk_widget_set_valign (child_view, GTK_ALIGN_FILL);
-
-  gtk_container_add (GTK_CONTAINER (event_box), child_view);
-
-  gtk_text_view_add_child_at_anchor (view, event_box, anchor);
+  gtk_text_view_add_child_at_anchor (view, frame, anchor);
 
   recursive_attach_view (depth + 1, GTK_TEXT_VIEW (child_view), anchor);
 }